package org.game.msgBuilder;

import java.util.ArrayList;
import java.util.List;

import org.bean.FriendInfo;
import org.bean.PlayerInfo;
import org.game.db.bean.Player;
import org.game.db.bean.PlayerData;
import org.game.db.proxy.bean.PlayerDataProxy;
import org.game.db.vo.PlayerDataVO.DiscreteVO;
import org.game.protobuf.s2c.S2CFriendMsg;
import org.game.protobuf.s2c.S2CFriendMsg.RespFriends;
import org.game.protobuf.s2c.S2CShareMsg.ChangeType;

/**
 * @author : DengYing
 * @CreateDate : 2017年12月4日 下午2:40:06
 * @Description ：好友消息构建器
 */
public class FriendMsgBuilder {
	/**
     * 创建单个好友信息
     */
    public static S2CFriendMsg.FriendInfo createFriendInfo(FriendInfo info) {
    	S2CFriendMsg.FriendInfo.Builder builder = S2CFriendMsg.FriendInfo.newBuilder();
    	builder.setCt(ChangeType.valueOf(info.getCt()))
    	.setPid(info.getPid())
    	.setName(info.getName())
    	.setLeaderCid(info.getLeaderCid())
    	.setFightPower(info.getFightPower())
    	.setLvl(info.getLvl())
    	.setLastLoginTime((int) (info.getLastLoginDate().getTime() / 1000))
    	.setLastHandselTime((int) (info.getLastHandselTime().getTime() / 1000))
    	.setReceive(info.isReceive())
    	.setStatus(info.getStatus())
    	.setOnline(info.isOnline())
    	.setTime((int) (info.getCreateDate().getTime() / 1000));
        return builder.build();
    }
    
    /**
     * 创建多个好友信息
     */
    public static List<S2CFriendMsg.FriendInfo> createFriendInfo(List<FriendInfo> infos) {
    	List<S2CFriendMsg.FriendInfo> list = new ArrayList<>(infos.size());
    	for (FriendInfo friendInfo : infos) {
    		list.add(createFriendInfo(friendInfo));
		}
    	return list;
    }
    
    
    /**
     * 创建单个推荐好友信息
     */
    public static S2CFriendMsg.FriendInfo createRecommendFriendInfo(PlayerInfo info) {
    	S2CFriendMsg.FriendInfo.Builder builder = S2CFriendMsg.FriendInfo.newBuilder();
    	builder.setCt(ChangeType.DEFAULT)
    	.setPid(info.getPid())
    	.setName(info.getName())
    	.setLeaderCid(info.getHelpHeroCid())
    	.setFightPower(info.getFightPower())
    	.setLvl(info.getLvl())
    	.setLastLoginTime((int) (info.getLastLoginDate().getTime() / 1000))
    	.setOnline(info.isOnline());
        return builder.build();
    }
    
    /**
     * 创建多个推荐好友信息
     */
    public static List<S2CFriendMsg.FriendInfo> createRecommendFriendInfo(List<PlayerInfo> infos) {
    	List<S2CFriendMsg.FriendInfo> list = new ArrayList<>(infos.size());
    	for (PlayerInfo playerInfo : infos) {
    		list.add(createRecommendFriendInfo(playerInfo));
		}
    	return list;
    }
    
    public static RespFriends createRespFriendsMsg(Player player,List<FriendInfo> friends){
    	RespFriends.Builder resp = RespFriends.newBuilder().addAllFriends(FriendMsgBuilder.createFriendInfo(friends));
    	PlayerData playerData = player.getPlayerDatasFkPlayerId();
    	PlayerDataProxy playerDataProxy = playerData.getPlayerDataProxy();
    	DiscreteVO discreteVO = playerDataProxy.getDiscreteVO();
		resp.setLastReceiveTime((int) (discreteVO.getLastGetFriendGiftDate().getTime()/1000));
		resp.setReceiveCount(discreteVO.getNowGetFriendGiftCount());
		return resp.build();
    }
}
